package cn.tedu.rms.orders.controller;

import cn.tedu.rms.orders.pojo.dto.OrdersQuery;
import cn.tedu.rms.orders.pojo.dto.OrdersSaveParam;
import cn.tedu.rms.orders.pojo.vo.OrdersVO;
import cn.tedu.rms.orders.service.OrdersService;
import cn.tedu.rms.base.response.JsonResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/orders")
public class OrdersController {
    @Autowired
    OrdersService ordersService;
    @PostMapping("insertOrders")
    public JsonResult insertOrders(OrdersSaveParam ordersSaveParam){
        log.debug("新增订单表:参数={}",ordersSaveParam);
        ordersService.insertOrders(ordersSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation(value = "通过条件查询订单表")
    @GetMapping("/select")
    public JsonResult selectOrders(OrdersQuery ordersQuery){
        log.debug("查询数据，用来回显={}",ordersQuery);
        List<OrdersVO> list =  ordersService.selectOrders(ordersQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "支付订单")
    @PostMapping("/pay")
    public JsonResult pay(OrdersSaveParam ordersSaveParam){
        log.debug("支付订单，参数={}",ordersSaveParam);
        ordersService.pay(ordersSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("selectByCondition")
    public JsonResult selectByCondition(OrdersQuery ordersQuery){
        log.debug("用户条件查询订单,参数:{}",ordersQuery);
        List<OrdersVO> ordersVOList = ordersService.selectOrdersByCondition(ordersQuery);
        return JsonResult.ok(ordersVOList);

    }
    @PostMapping("confirmOrder")
    public JsonResult confirmOrder(OrdersSaveParam ordersSaveParam){
        log.debug("顾客确认下单业务，参数：{}",ordersSaveParam);
        ordersService.confirmOrder(ordersSaveParam);
        return JsonResult.ok();
    }

    // 员工下单接口
    @PostMapping("confirmOrderEmp")
    public JsonResult staffInsertOrders(OrdersSaveParam ordersSaveParam){
        log.debug("员工下单，参数：{}",ordersSaveParam);
        ordersService.confirmOrderEmp(ordersSaveParam);
        return JsonResult.ok();
    }
    //更新订单
    @PostMapping("update")
    public JsonResult updateOrders(OrdersSaveParam ordersSaveParam){
        log.debug("更新订单，参数：{}",ordersSaveParam);
        ordersService.update(ordersSaveParam);
        return JsonResult.ok();
    }


}
